package com.gr.staffpm.charts;

import java.awt.Color;

import org.apache.wicket.model.LoadableDetachableModel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;


public class LoadableDetachableJFChart extends LoadableDetachableModel<JFreeChart> {

    private static final long serialVersionUID = 1L;
    private final JFreeChart chart;

    public LoadableDetachableJFChart(JFreeChart chart) {
        this.chart = chart;
    }

    @Override
    protected JFreeChart load() {
        if (chart.getPlot() instanceof XYPlot) {
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setDomainCrosshairVisible(true);
            plot.setRangeCrosshairVisible(true);

            XYItemRenderer r = plot.getRenderer();
            if (r instanceof XYLineAndShapeRenderer) {
                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
                renderer.setBaseShapesVisible(true);
                renderer.setBaseShapesFilled(true);
                renderer.setSeriesPaint(0, Color.BLUE);
            }
        }
        return chart;
    }

}
